//#include "stdafx.h"
#include "OrNodeModel.h"

COrNodeModel::COrNodeModel(void)
{
	Children.clear();
	Weights.clear();
}

COrNodeModel::~COrNodeModel(void)
{
}

int	COrNodeModel::MakeMissInformation(ModelTreeType &model, int Level)
{
	int		ChildCount;
	int		ret;

	// MissScore
	//this->Level = Level;
	ChildCount	= (int) Children.size();
	ModelCount	= ChildCount;
	for ( int i = 0; i < ChildCount; i++ )
	{
		CAndNodeModel	&ChildModel	= model.AndModels[Children[i]];

		ret				= ChildModel.MakeMissInformation(model, Level);
		MissSource		= i;
		MissLeafNode	= ChildModel.MissLeafNode;
	}

	return	1;
}

int COrNodeModel::SaveOrNodeModel(FILE *fpFile)
{
	int		ChildCount	= (int) Children.size();

	fprintf_s(fpFile, "::OrNodeModel %02d  \ton_level %d\n", OrNodeID, Level);
	fprintf_s(fpFile, "%6d\n", ChildCount);
	for ( int i = 0; i < ChildCount; i++ )
	{
		fprintf_s(fpFile, "%6d %e\n", Children[i], Weights[i]);
	}
	fprintf_s(fpFile, "\n");

	return	1;
}

int	COrNodeModel::ReadOrNodeModel(FILE *fpFile)
{
	int		ChildCount;
	char strTemp[10001];

	fscanf(fpFile, "%s%d%s%d", strTemp, &OrNodeID, strTemp, &Level);
	fscanf_s(fpFile, "%d", &ChildCount);
	Children.resize(ChildCount);
	Weights.resize(ChildCount);
	for ( int i = 0; i < ChildCount; i++ )
	{
		fscanf_s(fpFile, "%d%lf", &Children[i], &Weights[i]);
	}
	return	1;
}

